# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=yaml-cpp0.3

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.0
pkgrel=2
pkgdesc="A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64) - old version"
arch=('any')
url="https://code.google.com/p/yaml-cpp/"
license=("MIT")
provides=("${MINGW_PACKAGE_PREFIX}-yaml-cpp")
conflicts=("${MINGW_PACKAGE_PREFIX}-yaml-cpp")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "${MINGW_PACKAGE_PREFIX}-cmake"
    "${MINGW_PACKAGE_PREFIX}-boost")
options=('staticlibs' 'strip')
source=(http://yaml-cpp.googlecode.com/files/yaml-cpp-${pkgver}.tar.gz
    mingw-install-pkgconfig.patch)
md5sums=('9aa519205a543f9372bf4179071c8ac6'
         'acf096cb06ee28ecb730a8e0b0cf044d')

prepare() {
  cd ${srcdir}/yaml-cpp
  patch -p1 -i ${srcdir}/mingw-install-pkgconfig.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  mkdir $srcdir/build-${MINGW_CHOST}

  cd "$srcdir/build-${MINGW_CHOST}"
  ${MINGW_PREFIX}/bin/cmake.exe \
    ../yaml-cpp-${pkgver} \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DBUILD_SHARED_LIBS=OFF \
    ../yaml-cpp
  make
}

package() {
  cd "$srcdir/build-${MINGW_CHOST}"
  make -j1 install

  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  cd ${pkgdir}${MINGW_PREFIX}
  sed -i "s|$PREFIX_WIN|$MINGW_PREFIX|g" lib/pkgconfig/yaml-cpp.pc 
}
